import Mock from 'mockjs'

// 存放数据
let { userInfo } = Mock.mock({
    'userInfo': [{
        username: '漳卅',
        tel: '13800000001',
        password: '123456',
        'id': '@id',
        'img': '@image("150x150","@color","嗨嗨害")',
    }]
})
//   验证账号密码
Mock.mock('/user/login', 'post', (config) => {
    const req = JSON.parse(config.body)

    let res = {
        code: '200',
        msg: '登陆失败',
        id: '',
        img: '',
        tle: '',
        username: ''
    }
    // 判断返回对错返回数据
    userInfo.forEach(item => {
        if (item.tle == req.tle && item.password == req.password) {
            res.msg = '登录成功'
            res.id = item.id
            res.img = item.img
            res.tle = item.tle
            res.username = item.userName
            res.code = '200'
        } else {
            res.code = '300'
            res.msg = '登陆失败'
        }
    });
    return res
})